package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Clazz;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ClazzMapper {
    Page<Clazz> page(String name, LocalDate begin, LocalDate end);

    /**
     * 新增班级
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("INSERT INTO clazz(name, room, begin_date, end_date, master_id, subject, create_time, update_time)" +
            " VALUES (#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void insetClazz(Clazz clazz);

    /**
     * 根据ID查询班级接口
     */
    @Select("select * from clazz where id = #{id}")
    Clazz selectById(Integer id);


    /**
     * 修改班级
     */
    @Update("update clazz set name=#{name},room=#{room},begin_date=#{beginDate},end_date=#{endDate},master_id=#{masterId},subject=#{subject},update_time=#{updateTime} where id=#{id}")
    void updateClazz(Clazz clazz);

    /**
     * 删除班级
     */
    @Delete("delete from clazz where id=#{id}")
    void deleteById(Integer id);

    /**
     * 查询所有班级
     */
    @Select("select * from clazz")
    List<Clazz> selectAllClazz();

    @Select("select * from student where clazz_id = #{id} limit 1;")
    Clazz selectByStuId(Integer id);
}
